import requests


"""
deepseek-chat 模型已全面升级为 DeepSeek-V3，接口不变。 通过指定 model='deepseek-chat' 即可调用 DeepSeek-V3。
deepseek-reasoner 是 DeepSeek 最新推出的推理模型 DeepSeek-R1。通过指定 model='deepseek-reasoner'，即可调用 DeepSeek-R1
"""

API_URL = "https://api.deepseek.com/v1/chat/completions"  # 官方默认地址
API_KEY = "sk-7fd3867b959a49e69b63553b00598c8a"  # 从 https://platform.deepseek.com/ 获取

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

data = {
    "model": "deepseek-chat",  # 确认是否为免费模型
    "messages": [{"role": "user", "content": "你好，请介绍一下你自己"}],
    "temperature": 0.7,
    "max_tokens": 200  # 限制输出长度以节省额度
}

try:
    response = requests.post(API_URL, headers=headers, json=data)
    result = response.json()

    if "error" in result:
        print("API 错误:", result["error"].get("message", "未知错误"))
    else:
        print("回复:", result["choices"][0]["message"]["content"])

except Exception as e:
    print("请求失败:", str(e))